<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<style>
.ui-widget,.ui-widget .ui-widget {
	font-size: 11px !important;
}
</style>
	<title>Cadastro de Compras</title>
	<link rel="stylesheet" type="text/css" href="css/estilos.css" />
</h:head>
<body>
	<h:form id="form">
		<p:messages id="messages" showDetail="false" autoUpdate="true"
			closable="true" />
		<p:panel id="mCompraPanel" style="border: none;">

			<h3>Cadastro de Compras</h3>

			<h:panelGrid columns="6" cellpadding="2" style="border: 2px;">
				<h:outputText value="Nota Fiscal" />
				<h:outputText value="Serie" />
				<h:outputText value="Fornecedor* " />
				<h:outputText value="" />
				<h:outputText value="" />
				<h:outputLabel value="Cond.Pag. Fornecedor" />

				<p:inputMask id="mCompraNotaFiscal"
					value="#{beanCompra.compra.nota}" maxlength="4" size="10"
					mask="999.999.999" />
				<p:inputMask id="mCompraSerie" value="#{beanCompra.compra.serie}"
					maxlength="4" size="5" mask="999" />
				<p:inputText id="mCompraIdFornecedor"
					value="#{beanCompra.compra.fornecedor.id}" size="5">
					<p:ajax event="change" listener="#{beanCompra.hotFindFornecedor}"
						process="@this" update="mCompraFornecedor, mCompraCondicao" />
				</p:inputText>
				<p:inputText id="mCompraFornecedor"
					value="#{beanCompra.compra.fornecedor.nomeFantasia}" size="50"
					disabled="true" binding="#{beanCompra.fornecedor}" />

				<p:commandButton id="mCompraSelectFornecedor" icon="ui-icon-search"
					title="Selecionar Fornecedor" onclick="dConsultaFornecedor.show()" />
				<p:inputText id="mCompraCondicao"
					value="#{beanCompra.compra.fornecedor.condPagamento.descricao}"
					size="25" disabled="true" />
			</h:panelGrid>

			<br></br>

			<p:panel id="mCompraProdutos" header="Produtos">

				<h:panelGrid columns="10" cellpadding="2">

					<h:outputText value="Codigo" />
					<h:outputText value="Produto" />

					<h:outputText value="" />
					<h:outputText value="Unidade" />
					<h:outputText value="Quantidade*" />
					<h:outputText value="Preco*" />
					<h:outputText value="% IPI" />
					<h:outputText value="% ICMS" />
					<h:outputText value=" ICMS" />
					<h:outputText value="" />

					<p:inputText id="mCompraIdProduto"
						value="#{beanCompra.item.produto.id}" maxlength="40" size="5">
						<p:ajax event="change" listener="#{beanCompra.hotFindProduto}"
							process="@this"
							update="mCompraProduto, mCompraUnidade, mCompraPercIpi, mCompraPercIcms, mCompraIcms" />
					</p:inputText>
					<p:inputText id="mCompraProduto"
						value="#{beanCompra.item.produto.descricao}" size="50"
						disabled="true" binding="#{beanCompra.produto}" />
					<p:commandButton id="mCompraSelesctProduto" icon="ui-icon-search"
						title="Selecionar Produto" onclick="dConsultaProduto.show()"
						update="pcProdutoDManterProduto">
						<f:setPropertyActionListener target="#{beanProduto.compra}"
							value="true"></f:setPropertyActionListener>
					</p:commandButton>
					<p:inputText id="mCompraUnidade"
						value="#{beanCompra.item.produto.uniMedida}" size="5"
						disabled="true" />


					<p:inputText id="mCompraQuantidade"
						value="#{beanCompra.item.quantidade}" size="5" />
					<p:inputText id="mCompraPrecoCompra"
						value="#{beanCompra.item.produto.precoCompra}" size="5" />
					<p:inputText id="mCompraPercIpi" size="5" />
					<p:inputText id="mCompraPercIcms" size="5" />
					<p:inputText id="mCompraIcms" size="5" />
					<p:commandButton id="mComrpaAddProduto" icon="ui-icon-plus"
						title="Adicionar" action="#{beanCompra.addItem}"
						update="mCompraProdutos, mCompraTotalProd, mCompraTotalNota" />
				</h:panelGrid>

				<br></br>

				<p:dataTable emptyMessage="A compra nao possui produtos."
					value="#{beanCompra.itens}" var="item">
					<p:column headerText="Descricao">
						<h:outputText value="#{item.produto.descricao}" />
					</p:column>
					<p:column headerText="Quantidade">
						<h:outputText value="#{item.quantidade}" />
					</p:column>
					<p:column headerText="Preço Uni">
						<h:outputText value="#{item.precoUni}" />
					</p:column>
					<p:column headerText="Preco Total">
						<h:outputText value="#{item.valor}" />
					</p:column>
					<p:column width="10">
						<p:commandButton icon="ui-icon-trash"
							action="#{beanCompra.removeItem}" update=":form:mCompraProdutos">
							<f:setPropertyActionListener target="#{beanCompra.item}"
								value="#{item}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>

			<br></br>
			<p:separator />
			<h:panelGrid columns="7" cellpadding="5">

				<h:outputText value="Total Produtos" />
				<h:outputText value="Base ICMS" />
				<h:outputText value="ICMS" />
				<h:outputText value="Valor IPI" />
				<h:outputText value="Peso Bruto" />
				<h:outputText value="Peso Liq." />
				<h:outputText value="Total da Nota" />

				<p:inputText id="mCompraTotalProd" size="15" disabled="true"
					value="#{beanCompra.compra.subTotal}" />
				<p:inputText id="mCompraBaseIcms" size="15"
					value="#{beanCompra.compra.baseIcms}" />
				<p:inputText id="mCompraVicms" size="15"
					value="#{beanCompra.compra.icms}" />
				<p:inputText id="mCompraValorIpi" size="15"
					value="#{beanCompra.compra.ipi}" />
				<p:inputText id="mCompraPesoB" size="15"
					value="#{beanCompra.compra.pesoBruto}" />
				<p:inputText id="mCompraPesoL" size="15"
					value="#{beanCompra.compra.pesoLiq}" />
				<p:inputText id="mCompraTotalNota" disabled="true" size="15"
					value="#{beanCompra.compra.total}" />

			</h:panelGrid>

			<h:panelGrid columns="7" cellpadding="5">

				<h:outputText value="Tipo do Frete" />
				<h:outputText value="Tranportadora" />
				<h:outputText value="" />
				<h:outputText value="" />
				<h:outputText value="Valor Frete" />
				<h:outputText value="Outras Dispesas" />
				<h:outputText value="Seguro" />

				<p:selectOneMenu id="mCompraTipoFrete"
					value="#{beanCompra.compra.tipoFrete}">
					<f:selectItem itemLabel="Selecione" itemValue="" />
					<f:selectItems value="#{beanCompra.tipoFrete}" />
				</p:selectOneMenu>


				<p:inputText id="mCompraIdTranportadora" size="8"
					value="#{beanCompra.compra.transportadora.id}" />
				<p:inputText id="mCompraTransportadora" size="37" disabled="true"
					value="#{beanCompra.compra.transportadora.descricao}" />
				<p:commandButton icon="ui-icon-search" />
				<p:inputText id="mCompraValorFrete" size="15"
					value="#{beanCompra.compra.frete}" />
				<p:inputText id="mCompraOutrasDispesas" size="15"
					value="#{beanCompra.compra.outrasDispesas}" />
				<p:inputText id="mCompraSeguro" size="15"
					value="#{beanCompra.compra.seguro}" />

			</h:panelGrid>

			<br></br>
			<p:separator />

			<h:panelGrid columns="3" style="float: right;">
				<p:commandButton id="mCompraFinalizarCompra"
					value="Finalizar Compra" onclick="dCondCompra.show()" />
				<p:commandButton id="mCompraLimpar" value="Limpar"
					action="#{beanCompra.reinit}" update="@form" />
				<p:commandButton id="mCompraVoltar" value="Voltar"
					onclick="history.back()" />
			</h:panelGrid>


			<h:panelGrid columns="6" cellpadding="2" style="float: left;">
				<h:outputText value="Cadastro" />
				<p:inputText id="mCompraCadastro"
					value="#{beanCompra.compra.criacao}" size="7" disabled="true" />

				<h:outputText value="Ult. Alteracao" />
				<p:inputText id="mCompraAlteracao"
					value="#{beanCompra.compra.alteracao}" size="7" disabled="true" />

				<h:outputText value="Cancelamento" />
				<p:inputText id="mCompraCancelamento"
					value="#{beanCompra.compra.cancelamento}" size="7" disabled="true" />
			</h:panelGrid>

		</p:panel>

		<p:dialog header="Finalizar Compra" widgetVar="dCondCompra"
			id="mCompraDCondPagamento" resizable="false">
			<ui:include src="/condPagamento/pFinalizaCompra.xhtml"></ui:include>
		</p:dialog>

		<p:dialog header="Consultar Fornecedor"
			widgetVar="dConsultaFornecedor" id="mCompraDConsFornecedor"
			resizable="false">
			<ui:include src="/fornecedor/pConsultaFornecedor.xhtml"></ui:include>
		</p:dialog>

		<p:dialog header="Consultar Produto" widgetVar="dConsultaProduto"
			id="mCompraDConsProduto" resizable="false">
			<ui:include src="/produto/pConsultaProdutoCompra.xhtml"></ui:include>
		</p:dialog>

	</h:form>
</body>
</html>